﻿function gRand() { return Math.floor(Math.random() * 100000 + 1) }
var AjaxValidformUrl = "/Ajax/";


function WLRL() { window.location.reload(); }   

function randomString(len) {
    len = len || 32;
    var $chars = 'ABCDEFGHJKMNPQRSTWXYZabcdefhijkmnprstwxyz2345678';    /****默认去掉了容易混淆的字符oOLl,9gq,Vv,Uu,I1****/
    var maxPos = $chars.length;
    var pwd = '';
    for (i = 0; i < len; i++) {
        pwd += $chars.charAt(Math.floor(Math.random() * maxPos));
    }
    return pwd;
}

//是否存在指定函数 
function isExitsFunction(funcName) {
    try {
        if (typeof (eval(funcName)) == "function") {
            return true;
        }
    } catch (e) { }
    return false;
}
//是否存在指定变量 
function isExitsVariable(variableName) {
    try {
        if (typeof (variableName) == "undefined") {
            //alert("value is undefined"); 
            return false;
        } else {
            //alert("value is true"); 
            return true;
        }
    } catch (e) { }
    return false;
}


//-------------------------------------------------------------------------------
//---版本2.1
//---更新20150406
//---增加正整数判断

//---自定义js函数集
//---版本2.0
//---更新20150309
//-------------------------------------------------------------------------------

var nsJs =
    {
        'layerCofig':function(){ layer.config({extend: ['skin/seaning/style.css']});},
        'msgshow': function (msgStr, tips, isSucc) {   //layer1.90  
            nsJs.layerCofig();
            var shift = 4;
            if (isSucc == 11) shift = 6;
            //1-正确,2-失败,0-提示
            layer.alert(msgStr, {
                skin: 'layer-ext-seaning',
                title: tips,
                icon: isSucc,
                shift: shift //动画类型
            });           
        },
        'alert':function(msg){
            nsJs.layerCofig();
            layer.alert(msg, { skin: 'layer-ext-seaning', title: "&nbsp;", icon: 6, shade: [0.8, "#000"], shadeClose: true });
        },

        'ask': function (tips, msgStr, siA, siB, icon) {  //询问层
            nsJs.layerCofig();
            layer.confirm(msgStr, {
                skin: 'layer-ext-seaning',
                title: tips,
                icon:icon,
                btn: [siA,siB], //按钮
                shade:true //不显示遮罩
            }, function(){
                layer.msg('的确很重要', {icon: 1});
            }, function(){
                layer.msg('奇葩么么哒', {shift: 6});
            });
        },

        //询问框
        'openAboutBoxV2': function (title,ico) {     //190版
            layer.confirm('您是如何看待前端开发？', {
                btn: ['重要', '奇葩'], //按钮
                border: [10, 0.2, "#000"],
                shade: [0.5, "#000"], //不显示遮罩
                icon:1,
                skin: 'layer-ext-seaning',
            }, function () {
               // layer.msg('的确很重要', { icon: 1 });
            }, function () {
              //  layer.msg('奇葩么么哒', { shift: 6 });
            })
        },
        'passwordStrengthen':function(oStr){
            var s = randomString(8);
            var a = s.substring(0, 4);
            var b = s.substring(4, 8);
            return a + oStr + b;
        },
        'openLayeriframeV2': function (title, width, height, url) {            //iframe层 v1.90
            layer.open({
                type: 2,
                title: title,
                shadeClose:false,
                shade: 0.8,
                area: [ width + 'px', height + 'px'],
                content: url        //iframe的url
            });
        },
        'openLayeriframeV1': function (title, width, height, url) {   //1.85版          
            $.layer({
                type: 2,
                border: [10, 0.2, "#000"],           //border的值分别为：[边框大小, 透明度, 颜色     不显示border，设置 border: [0] 即可    
                title: title,                          //title: ['标题', 'background:#c00;'],          不显示标题栏，配置title: false 即可
                shade: [0.6, '#000'],                   //不想显示遮罩，配置shade: [0]即可
                shadeClose: false,
                closeBtn:[0,true],
                iframe: { src: url },
                area: [ width + 'px', height + 'px']
            });
          
        },
        'openLayer': function (rType, rshadeClose, rtitle, rcloseBtnType, rcloseBtnKg, rshade, rborder, rareaWidth, rareaHeight, rfadIn, rshift, rSrc) {  //弹出层

            if (rshade<0) rshade = 0.8;
            if (rshift.length < 1) rshade = "top";
            if (rfadIn.length < 1) rfadIn = "500";     
            
            $.layer({
                type: rType,
                shadeClose: rshadeClose,//false,true
                title: rtitle,
                closeBtn: [rcloseBtnType, rcloseBtnKg],
                shade: [0.8, '#000'],
                border: [rborder],
                area: [ rareaWidth + 'px', rareaHeight + 'px'],
                fadIn: 500,
                shift: rshift ,
                iframe: { src: rSrc }
            });
        },
        'IsPositiveInteger': function (s) {   //正整数判断
            var r = /^[0-9]*[1-9][0-9]*$/;
            return r.test(s);
        },
        'ValidFormTipsSpan': function () {   //绑定text验证信息显示窗
            $(".text-box").append("<span class=\"Validform_checktip\"><\/span>");
        },
        'ValidFormBound': function (vfObj, vfdataType, vfNullmsg, vfErrmsg, vfSucmsg, vfRecheck) {
            if(vfNullmsg.indexOf("同意")<0) vfNullmsg = "请填写" + vfNullmsg;
            vfObj.attr("nullmsg", vfNullmsg);
            vfObj.attr("datatype", vfdataType);
            if (vfErrmsg.length < 1) vfErrmsg = vfNullmsg; else vfErrmsg = "请填写" + vfErrmsg;
            vfObj.attr("errormsg", vfErrmsg);          
            if (vfRecheck.length > 1) vfObj.attr("recheck", vfRecheck);
            if (vfSucmsg.length > 0) vfObj.attr("sucmsg", vfSucmsg);
        },
        'ValidFormRealTime': function (vfObj, vfName, vfValue, vfErrmsg) {
            //ajaxurl="/Inc/AjaxValidform.aspx?ID=0&amp;msg=%e5%91%98%e5%b7%a5%e5%b7%a5%e5%8f%b7"            
            var tmpUrl = AjaxValidformUrl + "?";    
            if (vfValue !="")
                tmpUrl = tmpUrl + vfName + "=" + vfValue + "&msg=" + encodeURIComponent(vfErrmsg);
            else
                tmpUrl = tmpUrl + "msg=" + encodeURIComponent(vfErrmsg);
            vfObj.attr('ajaxurl', tmpUrl);
         //   alert(tmpUrl);
            tmpUrl = "";
        },
        'wordCount': function (txtInputBox, txtNumTips, maxNum) {
            var $tex = $("#" + txtInputBox); var ie = jQuery.support.htmlSerialize; var ChineseStrNum = 0; var CharNum = 0; var texts = 0; var num = 0; var sets = null;
            //$tex.val("");
            if (ie) { $tex[0].oninput = changeNum; } else { $tex[0].onpropertychange = changeNum; }
            $tex.focus(function () {
                if ($tex.val() == "") { $("#" + txtNumTips).html("您还可以输入的字数<span>" + maxNum + "</span>"); }
                else
                { changeNum() }
            })
            // $tex.blur(function () { if ($tex.val() == "") { $("#" + txtNumTips).html("请在下面输入您的文字："); } })

            function changeNum() {
                ChineseStrNum = ($tex.val().replace(/\w/g, "")).length; CharNum = $tex.val().length - ChineseStrNum; total = ChineseStrNum * 2 + CharNum;
                if (total < maxNum || total == maxNum) { texts = Math.ceil((maxNum - total)); $("#" + txtNumTips).html("您还可以输入的字数<span>" + texts + "</span>").children().css({ "color": "blue" }); } else { $tex.val($tex.val().substr(0, maxNum)); }
            }
        },

        'TabChange': function (TabKG, TabObj,TabShow, onClassName) {
            //alert(onClassName);
            if (onClassName == undefined) onClassName = "on";
            $(TabObj).find("div" + ":eq(0)").show()
            $(TabKG).find("li").hover(function () {
                $(TabKG).find("li").removeClass(onClassName);
                $(this).addClass(onClassName);
                var index = $(this).index();
             
                $(TabObj + " " + TabShow).hide();
                $(TabObj + " " + TabShow + ":eq(" + index + ")").show();  
            });     
        },

        'TabChangeClick': function (TabKG, TabObj, onClassName) {
            if (onClassName == undefined) onClassName = "on";
            $(TabObj).find("div" + ":eq(0)").show()
            $(TabKG).find("li").click(function () {
                $(TabKG).find("li").removeClass(onClassName);
                $(this).addClass(onClassName);
                var index = $(this).index();             
                $(TabObj).find("div").hide();
                $(TabObj).find("div" + ":eq(" + index + ")").show();
                $(TabObj).find("div" + ":eq(" + index + ")").find("div").show();
            });           
        },
        'CheckSelectAll': function (doCheckobj, bedoCheckobjName) {
            //alert("ccc");
            $(doCheckobj).bind("click", function () {
                var checked = $(this).is(":checked");
                $('input[name="' + bedoCheckobjName + '"]').attr("checked", this.checked);
            });
        },
        'IsCheckSelected': function (bedoCheckobjName) {//判断是否有选择checkbox       
            var obj = $('input[name="' + bedoCheckobjName + '"]');            
            if (obj.length > 0) {
                for (var i = 0; i < obj.length; i++) {
                    if (obj[i].checked == true) return true;
                }
            }           
            return false;         
        },
        'singleCheckSelected': function (doneObjName,bedoCheckobj) {
            $('input[name="' + doneObjName + '"]').click(function () { if ($(this).is(":checked") == false) { $(bedoCheckobj).attr("checked", false); } })
        },
        'IsCheckSelectedByBtnClick': function (ObjBtn, ObjCheckName) {
            $(ObjBtn).click(function () {              
                var isTrue = false;
                var obj = $('input[name="' + ObjCheckName + '"]');
                if (obj.length > 0) {
                    for (var i = 0; i < obj.length; i++) {
                        if (obj[i].checked == true) return true;
                    }
                }
                alert("请选择要删除的数据。");
                return false;
            });
        },
        'CreatDiv': function (divID, divClass) {
                var oDiv = document.createElement("div");
                oDiv.className = divClass;
                oDiv.id = divID;              
                document.body.appendChild(oDiv);          
        },
        'GetMapPonit': function (checkCity, checkKey, resultObj) {           
            if (checkCity.length > 0 && checkKey.length > 0) {
                var gajaxurl = AjaxUrl + "?Menu=GetMapPonit&City=" + encodeURIComponent(checkCity) + "&Key=" + encodeURIComponent(checkKey);
                $.get(gajaxurl, function (data) { if (data != "0") $(resultObj).val(data); });
                return true;
            }
            else
                return false;
        },
        'Stopwatch': function (obj) {
            var timeNum = obj.html();

        },
        'len': function (s) {
            var l = 0; var a = s.split("");
            for (var i = 0; i < a.length; i++) {
                if (a[i].charCodeAt(0) < 299) {
                    l++;
                } else {
                    l += 2;
                }
            }
            return l;
        },
        'getbodysize': function (gtype) {
            var s = 0;
            switch(gtype)
            {
                case "1": s = $(window).height(); break;//浏览器时下窗口可视区域高度
                case "2": s = $(document).height(); break;//浏览器时下窗口文档的高度
                case "3": s = $(document.body).height(); break;//浏览器时下窗口文档body的高度
            }
           // alert($(window).height()); //浏览器时下窗口可视区域高度
          //  alert($(document).height()); //浏览器时下窗口文档的高度
          //  alert($(document.body).height());//浏览器时下窗口文档body的高度
          //  alert($(document.body).outerHeight(true));//浏览器时下窗口文档body的总高度 包括border padding margin
          //  alert($(window).width()); //浏览器时下窗口可视区域宽度
           // alert($(document).width());//浏览器时下窗口文档对于象宽度
         //   alert($(document.body).width());//浏览器时下窗口文档body的高度
         //   alert($(document.body).outerWidth(true));//浏览器时下窗口文档body的总宽度 包括border padding margin
          //  alert($(document).scrollTop()); //获取滚动条到顶部的垂直高度
            //   alert($(document).scrollLeft()); //获取滚动条到左边的垂直宽度
            return s;
        }
    }


function len(s) {
    var l = 0; var a = s.split("");
    for (var i=0;i<a.length;i++) {
        if (a[i].charCodeAt(0)<299) {
            l++;
        } else {
            l+=2;
        }
    }
    return l;
}